package com.linsen.core.feign.config;

import com.linsen.core.feign.endpoint.FeignClientEndpoint;
import com.linsen.core.common.annotation.AutoConfiguration;
import feign.Feign;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.LinsenFeignClientsRegistrar;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
 * Feign配置类
 *
 * @author zhaoyong
 * @date 2023/3/13
 */
@AutoConfiguration
@ConditionalOnClass(Feign.class)
@Import(LinsenFeignClientsRegistrar.class)
@AutoConfigureAfter(EnableFeignClients.class)
public class LinsenFeignAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnAvailableEndpoint
    public FeignClientEndpoint feignClientEndpoint(ApplicationContext context) {
        return new FeignClientEndpoint(context);
    }
}
